package com.dragons.spring5.aop.xml_annotation;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@Component
@Aspect
@Order(3)
public class UserProxy {

//    //@Before 注解表示作为前置通知
//    @Before(value = "execution(* com.dragons.spring5.aop.xml.User3.add(..))")
//    public void before() { System.out.println(".........前置通知"); }
//    //环绕通知
//    @Around(value = "execution(* com.dragons.spring5.aop.xml.User3.add(..))")
//    public void around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
//        System.out.println(">>>>环绕之前.....");
//        proceedingJoinPoint.proceed(); /**被增强的方法执行*/
//        System.out.println(">>>>环绕之后.....");
//    }
//    //最终通知
//    @After(value = "execution(* com.dragons.spring5.aop.xml.User3.add(..))")
//    public void after() { System.out.println(" .........最终通知"); }
//    //异常通知
//    @AfterThrowing(value = "execution(* com.dragons.spring5.aop.xml.User3.add(..))")
//    public void afterThrowing() { System.out.println(".........异常通知"); }
//    //后置通知（返回通知）
//    @AfterReturning(value = "execution(* com.dragons.spring5.aop.xml.User3.add(..))")
//    public void afterReturning() { System.out.println(".........后置通知"); }

    //相同切入点抽取
    @Pointcut(value = "execution(* com.dragons.spring5.aop.xml_annotation.User3.add(..))")
    public void pointdemo() {}

    @Before(value = "pointdemo()")
    public void before() { System.out.println(".........前置通知"); }
    @Around(value = "pointdemo()")
    public void around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        System.out.println(">>>>环绕之前.....");
        proceedingJoinPoint.proceed(); /**被增强的方法执行*/
        System.out.println(">>>>环绕之后.....");
    }
    @After(value = "pointdemo()")
    public void after() { System.out.println(" .........最终通知"); }
    @AfterThrowing(value = "pointdemo()")
    public void afterThrowing() { System.out.println(".........异常通知"); }
    @AfterReturning(value = "pointdemo()")
    public void afterReturning() { System.out.println(".........后置通知"); }
}